package juc.future;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author fangbin
 * @desc
 * @date 2020/7/1 8:16
 */
public class FutureTaskDemo {
    public static void main(String[] args) {

        Task task  = new Task();
        FutureTask futureTask = new FutureTask(task);
        Thread t1 = new Thread(futureTask);
        t1.start();
        try {
            System.out.println( futureTask.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

}


class Task implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        Thread.sleep(3000);
        int sum=0;
        for(int i=0;i<100;i++){
            sum+=i;
        }
        return sum;
    }
}